<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<%--
  Created by IntelliJ IDEA.
  User: bobo
  Date: 16-10-27
  Time: 下午2:30
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <jsp:include page="../layout/head.jsp" >
        <jsp:param name="title" value="类别信息" />
    </jsp:include>
    <style>
        .cp{
            float: left;
        }
        .cm{
            float: left;
            font-size:18px;
        }
    </style>
</head>
<body>
<div class="panel admin-panel">
    <div class="panel-head"><strong><span class="icon-pencil-square-o"></span> 类别信息</strong></div>
    <div class="body-content">
        <div class="form-group">
            <div class="label">
                <label>
                    <div class="cp">
                        <img src="${category.photo.img}" width="80px" height="80px">
                    </div>
                    <div class="cm">
                        ID:${category.id}<br>
                        名称：${category.name}<br>
                        状态：
                        <c:if test="${category.status==0}">禁用</c:if>
                        <c:if test="${category.status==1}">启用</c:if>
                        <br>
                    </div>
                </label>
            </div>
        </div>
    </div>
    <div class="padding border-bottom">
        <ul class="search" style="padding-left:10px;">
            <li> <a class="button border-main icon-plus-square-o" href="${pageContext.request.contextPath}/admin/tag/add"> 添加标签</a> </li>
            <li> <a class="button border-green icon-pencil-square-o" href="${pageContext.request.contextPath}/admin/category/upd?id=${category.id}"> 更新类别</a> </li>
        </ul>
    </div>
    <table class="table table-hover text-center">
        <tr>
            <th>标签名</th>
            <th>标签状态</th>
            <th>操作</th>
        </tr>
        <c:forEach items="${category.tags}" var="tag">
            <tr>
                <td>${tag.name}</td>
                <td>
                    禁用<input type="radio" class="${tag.id}" name="${tag.id}status" value="0" ${tag.status ==0 ?"checked":""} onchange="radioValue(this)"><br>
                    启用<input type="radio" class="${tag.id}" name="${tag.id}status" value="1" ${tag.status ==1 ?"checked":""} onchange="radioValue(this)">
                </td>
                <td>
                    <a class="button border-main" href="${pageContext.request.contextPath}/admin/tag/upd?id=${tag.id}">更新</a>
                    <a class="button border-red" href="javascript:void(0);" onclick="del(${tag.id})">删除</a>
                </td>
            </tr>
        </c:forEach>
    </table>
</div>
<script>
    function radioValue(node) {
        $.ajax({
            url: "${pageContext.request.contextPath}/admin/tag/changeStatus",
            type: "get",
            data: {"id": node.className, "status": node.value},
            success:function (data) {
                if(data == "true") {
                    alert("修改成功");
                }
            },
            error: function () {
                alert("修改失败");
            }
        })
    }
    function del(id) {
        if(confirm('删除后不可恢复')){
            $.ajax({
                url:"${pageContext.request.contextPath}/admin/tag/del",
                type:"get",
                data:{"id":id},
                success:function (data) {
                    if(data == "true"){
                        alert("删除成功");
                        window.location.reload();
                    }else
                        if(data == "false"){
                        alert("删除失败,正在使用中，不能删除");
                    }
                },
                error: function () {
                    alert("删除失败");
                }
            })
        }else {
            return false;
        }
    }
</script>
</body>
</html>
